function HandleSpreadSearch(gui, user, date, options, data) {
  this._gui = gui;
  this._user = user;
  this._date = date;
  this._options = options;
  this._data = data;
  
  this._popupBox = new ModulePopupBoxSimple();
  
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : function() {};
  this._search = (options && options.search) ? options.search : null;
  if (!this._search) {
    this._search = { customerId: '',
                     parcelNo: '',
                     task: '',
                     dateFrom: '',
                     dateTo: ''
                   };
  }
  
  this._cond = data['cond'];
  this._models = this._data['pz_model'];
  this._states = this._data['pz_model_state'];

  this._createElements();
}

HandleSpreadSearch.prototype._createElements = function() {
  var _self = this;
  this._gui.customerId.value = this._search.customerId;
  this._gui.task.value = this._search.task;
  this._gui.parcelNo.value = this._search.parcelNo;
  
  this._gui.customerId.onchange = function(e) { _self._search.customerId = this.value; };
  this._gui.customerId.onkeypress = function(e) { _self._search.customerId = this.value;
                                                  var code = DOMUtils.getEventCode(e);
                                                  if (code == 13) {
                                                    _self._callbackFunc(_self._search);
                                                  } else {
                                                    var div = document.createElement('div');
                                                    var pos1 = DOMUtils.findPos(_self._gui.customerId);
                                                    var pos = [pos1[0] + 1, pos1[1] + 82];
                                                    var query = "SELECT DISTINCT t.customer_id as customer_id FROM pz_task as t WHERE 1 = 1 AND " + '((t.customer_id LIKE \'%' + _self._gui.customerId.value + '%\'))' + ' AND ' + ((_self._cond) ? _self._cond : '1=1') + " ";
                                                    MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                                    new ModuleDialogSearchResult(document, div, 200, null, _self._user, _self._date, { item: _self._gui.customerId, query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._search.customerId = _self._gui.customerId.value; }}, _self._data);
                                                  }
                                                };
  this._gui.parcelNo.onchange = function(e) { _self._search.parcelNo = this.value; };
  this._gui.parcelNo.onkeypress = function(e) { _self._search.parcelNo = this.value;
                                                  var code = DOMUtils.getEventCode(e);
                                                  if (code == 13) {
                                                    _self._callbackFunc(_self._search);
                                                  } else {
                                                    var div = document.createElement('div');
                                                    var pos1 = DOMUtils.findPos(_self._gui.parcelNo);
                                                    var pos = [pos1[0] + 1, pos1[1] + 82];
                                                    var query = "SELECT DISTINCT t.code  FROM pz_task as t WHERE 1 = 1 AND " + '((t.code LIKE \'%' + _self._gui.parcelNo.value + '%\'))' + ' AND ' + ((_self._cond) ? _self._cond : '1=1') + " ";
                                                    MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                                    new ModuleDialogSearchResult(document, div, 200, null, _self._user, _self._date, { item: _self._gui.parcelNo, query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._search.parcelNo = _self._gui.parcelNo.value; }}, _self._data);
                                                  }
                                                };
  this._gui.task.onchange = function(e) { _self._search.task = this.value; };
  this._gui.task.onkeypress = function(e) { _self._search.task = this.value;
                                            var code = DOMUtils.getEventCode(e);
                                            if (code == 13) {
                                              _self._callbackFunc(_self._search);
                                            } else {
                                              var div = document.createElement('div');
                                              var pos1 = DOMUtils.findPos(_self._gui.task);
                                              var pos = [pos1[0] + 1, pos1[1] + 82];
                                              var query = "SELECT DISTINCT s.name FROM pz_model_state as s LEFT JOIN pz_model as m ON m.id = s.model_id LEFT JOIN pz_task as t ON t.model_id = m.id WHERE 1 = 1" + ' AND ' + ((_self._cond) ? _self._cond : '1=1') + " ";
                                              MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                              new ModuleDialogSearchResult(document, div, 330, null, _self._user, _self._date, { item: _self._gui.task, query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._search.task = _self._gui.task.value; }}, _self._data);
                                            }
                                          };

  this._gui.dateFrom.value = (this._search.dateFrom) ? SimpleDate.format(this._search.dateFrom) : '';
  this._gui.dateFrom.onclick = function() { var context = this;
                                            _self._changeDate.call(_self, this, _self._search.dateFrom, function(sd) { _self._search.dateFrom = sd; context.focus(); }, false);
                                            return false;
                                          };
  this._gui.dateFrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                if (code == 13) {
                                                  _self._callbackFunc(_self._search);
                                                }
                                              };
  this._gui.dateTo.value = (this._search.dateTo) ? SimpleDate.format(this._search.dateTo) : '';
  this._gui.dateTo.onclick = function() { var context = this;
                                          _self._changeDate.call(_self, this, _self._search.dateTo, function(sd) { _self._search.dateTo = sd; context.focus(); }, false);
                                          return false;
                                        };
  this._gui.dateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                              if (code == 13) {
                                                _self._callbackFunc(_self._search);
                                              }
                                            };
  this._gui.button.onclick = function() { _self._callbackFunc(_self._search); };
};

HandleSpreadSearch.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandleSpreadSearch.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandleSpreadSearch.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};

HandleSpreadSearch.toSql = function(search, models, states) {
  return escape((search.customerId != '') ? ('t.customer_id =' + search.customerId) : '1 = 1') + ' AND ' + escape((search.parcelNo != '') ? ('t.code =\'' + search.parcelNo + '\'') : '1 = 1') + ' AND ' + ((search.task != '') ? PPublishUtils.lookup(search.task, models, states) : '1 = 1') + ' AND ' + ((search.dateFrom) ? 't.created_date >= \'' + SimpleDate.toStamp(search.dateFrom)+ '\'' : '1 = 1') + ' AND ' + ((search.dateTo) ? 't.created_date <= \'' + SimpleDate.toStamp(search.dateTo) + '\'' : '1 = 1');
};